package com.example.mapper;

import com.example.bean.Venue;
import com.example.bean.VenueBooking;
import com.example.bean.VenueOrder;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface VenueMapper {

    //查询全部场地
    @Select("select * from venue")
    List<Venue> queryAllVenue();

    //通过ID查询场地
    @Select("select * from venue where venueId=#{venueId}")
    Venue queryVenueById(@Param("venueId") int venueId);


    //通过userID查询场地
    @Select("select * from venue where id = #{user}")
    List<Venue> queryVenueByUserId(@Param("user") int user);

    //通过名字模糊查询场地
    @Select("select * from venue where venueName like #{venueName}")
    List<Venue> queryVenueByName(@Param("venueName") String venueName);

    //添加场地
    @Insert("insert into venue (venueName,venueLocation,charges,announcement,\n" +
            "weeklyInfo,state,id,equipmentId,eventsId)\n" +
            "values (#{venueName},#{venueLocation},#{charges},#{announcement},\n" +
            "#{weeklyInfo},#{state},#{user},#{equipment},#{events});")
    int addVenue(Venue venue);

    //删除场地
    @Delete("delete from venue where venueId=#{venueId}")
    int deleteVenue(@Param("venueId") int venueId);

    //修改场地
    @Update("update venue set venueName=#{venueName}, venueLocation=#{venueLocation},charges=#{charges},\n" +
            "announcement=#{announcement},weeklyInfo=#{weeklyInfo},state=#{state},id=#{user},\n" +
            "equipmentId=#{equipment},eventsId=#{events}\n" +
            "where venueId=#{venueId};")
    int updateVenue(Venue venue);

    //更改场地状态
    @Update("update venue set state = #{state} where venueId = #{venueId}")
    int updateVenueState(@Param("venueId") int venueId, @Param("state") int state);

    //查询场地费用
    @Select("select charges from venue where venueId = #{venueId}")
    String venueCharges(@Param("venueId") int venueId);

    String announcement();

    //查询场地一周信息
    @Select("select weeklyInfo from venue where venueId = #{venueId}")
    String weeklyInfo(@Param("venueId") int venueId);

    //预定场地，保存订单信息
    @Insert("insert into venueorder (startTime,endTime,countTime,charges,countCharges,venueId)" +
            "values(#{startTime},#{endTime},#{countTime},#{charges},#{countCharges},#{venueId},)")
    int venueBook(VenueOrder venueOrder);


    //保存订单信息
    @Insert("insert into venueorder (startTime,endTime,countTime,charges,countCharges,venueId，orderState)" +
            "values(#{startTime},#{endTime},#{countTime},#{charges},#{countCharges},#{venueId},#{orderState})")
    int saveVenueOrder(VenueOrder venueOrder);

    //预定场地
    @Insert("insert into venuebooking (userId,venueId,startTime,endTime)" +
            " values(#{userId},#{venueId},#{startTime},#{endTime})")
    int saveVenueBooking(VenueBooking venueBooking);

    //开始计时
    @Insert("insert into venueorder (id,venueId,startTime,charges, orderState)" +
            " values(#{id},#{venueId},#{startTime},#{charges}, 0)")
    int newVenueBooking(VenueOrder venueOrder);

    @Select("select * from venueOrder where venueOrderId = #{venueOrderId}")
    VenueOrder selectByOrderId(@Param("venueOrderId") int venueOrderId);

    @Update("update venueorder set countTime=#{countTime}, countCharges=#{countCharges}, endTime = #{endTime}, orderState = #{orderState} where venueOrderId = #{venueOrderId}")
    int updateVenueOrder(VenueOrder venueOrder);

    //取消预定
    @Delete("delete from venuebooking where id=#{id}")
    int cancelBook(int userId);

    //查询预定信息
    @Select("select * from venuebooking")
    List<VenueBooking> queryVenueBooking();

    //通过userID查询场地
    @Select("select * from venueorder where id = #{id} and orderState = 0")
    List<VenueOrder> queryVenueOrderByUserId(@Param("id") int id);

    @Select("select * from venueorder where orderState=1")
    List<VenueOrder> queryAllVenueOrder();

}
